
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:ymApp/common/global.dart';
import 'MyMainScreen.dart';
import 'common/size_fit.dart';
import 'router/routes.dart';
import 'package:ymApp/public.dart';
import 'package:flutter_bmfbase/BaiduMap/bmfmap_base.dart'
    show BMFMapSDK, BMF_COORD_TYPE;

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  Global.init().then((e) => runApp(MyApp()));
  BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL);
}
//void main() => runApp(Global.init().then((e) => MyApp()));

class MyApp extends StatelessWidget {
  MyApp() {
    //  创建路由对象
    final router = Router();
    // 配置Routes 注册管理
    Routes.configureRoutes(router);
    //将生成的router给全局化
    Routes.router = router;
  }

  _saveData() async {
    var prefs = await SharedPreferences.getInstance();
    prefs.setString('token', '123123456');
  }

  @override
  Widget build(BuildContext context) {
    print('适配初始化');
    this._saveData();

    // 适配初始化
    MySizeFit.initialize();
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (ctx) => UserProvider()),
      ],
      child: MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
          visualDensity: VisualDensity.adaptivePlatformDensity,
        ),
        builder: BotToastInit(), //1.调用BotToastInit
        navigatorObservers: [BotToastNavigatorObserver()], //2.注册路由观察者
        onGenerateRoute: Routes.router.generator,
        home: MyMainScreen(),
      ),
    );
  }
}



